<html>
<head>
<title>Run.java</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
.s0 { color: #cf8e6d;}
.s1 { color: #bcbec4;}
.s2 { color: #bcbec4;}
.s3 { color: #6aab73;}
.s4 { color: #2aacb8;}
.s5 { color: #7a7e85;}
</style>
</head>
<body bgcolor="#1e1f22">
<table CELLSPACING=0 CELLPADDING=5 COLS=1 WIDTH="100%" BGCOLOR="#606060" >
<tr><td><center>
<font face="Arial, Helvetica" color="#000000">
Run.java</font>
</center></td></tr></table>
<pre><span class="s0">package </span><span class="s1">school</span><span class="s2">;</span>
<span class="s0">import </span><span class="s1">java</span><span class="s2">.</span><span class="s1">util</span><span class="s2">.</span><span class="s1">ArrayList</span><span class="s2">;</span>
<span class="s0">import </span><span class="s1">java</span><span class="s2">.</span><span class="s1">util</span><span class="s2">.</span><span class="s1">Random</span><span class="s2">;</span>
<span class="s0">public class </span><span class="s1">Run </span><span class="s2">{</span>
    <span class="s0">public static void </span><span class="s1">main</span><span class="s2">(</span><span class="s1">String</span><span class="s2">[] </span><span class="s1">args</span><span class="s2">) {</span>
       <span class="s1">ClassRoom classRoom </span><span class="s2">= </span><span class="s0">new </span><span class="s1">ClassRoom</span><span class="s2">(</span><span class="s3">&quot;java班&quot;</span><span class="s2">);</span>
       <span class="s1">Group group1 </span><span class="s2">= </span><span class="s0">new </span><span class="s1">Group</span><span class="s2">(</span><span class="s4">1</span><span class="s2">);</span>
       <span class="s1">Group group2 </span><span class="s2">= </span><span class="s0">new </span><span class="s1">Group</span><span class="s2">(</span><span class="s4">2</span><span class="s2">);</span>
       <span class="s1">group1</span><span class="s2">.</span><span class="s1">addstudent</span><span class="s2">(</span><span class="s0">new </span><span class="s1">Student</span><span class="s2">(</span><span class="s3">&quot;宗义&quot;</span><span class="s2">,</span><span class="s4">1</span><span class="s2">));</span>
        <span class="s1">group1</span><span class="s2">.</span><span class="s1">addstudent</span><span class="s2">(</span><span class="s0">new </span><span class="s1">Student</span><span class="s2">(</span><span class="s3">&quot;王五&quot;</span><span class="s2">,</span><span class="s4">2</span><span class="s2">));</span>
        <span class="s1">group2</span><span class="s2">.</span><span class="s1">addstudent</span><span class="s2">(</span><span class="s0">new </span><span class="s1">Student</span><span class="s2">(</span><span class="s3">&quot;老刘&quot;</span><span class="s2">,</span><span class="s4">3</span><span class="s2">));</span>
        <span class="s1">group2</span><span class="s2">.</span><span class="s1">addstudent</span><span class="s2">(</span><span class="s0">new </span><span class="s1">Student</span><span class="s2">(</span><span class="s3">&quot;漆黑&quot;</span><span class="s2">,</span><span class="s4">4</span><span class="s2">));</span>
        <span class="s1">classRoom</span><span class="s2">.</span><span class="s1">addGroup</span><span class="s2">(</span><span class="s1">group1</span><span class="s2">);</span>
        <span class="s1">classRoom</span><span class="s2">.</span><span class="s1">addGroup</span><span class="s2">(</span><span class="s1">group2</span><span class="s2">);</span>
        <span class="s5">//随机抽取小组</span>
        <span class="s1">Group randomGroup </span><span class="s2">= </span><span class="s1">classRoom</span><span class="s2">.</span><span class="s1">getRandomGroup</span><span class="s2">();</span>
        <span class="s1">System</span><span class="s2">.</span><span class="s1">out</span><span class="s2">.</span><span class="s1">println</span><span class="s2">(</span><span class="s3">&quot;随机抽取小组的id为&quot; </span><span class="s2">+ </span><span class="s1">randomGroup</span><span class="s2">.</span><span class="s1">getGroupId</span><span class="s2">());</span>
        <span class="s5">//随机从小组中抽取学生</span>
        <span class="s1">Student randomStudentFromGroup </span><span class="s2">= </span><span class="s1">classRoom</span><span class="s2">.</span><span class="s1">getRandomStudentFromGroup</span><span class="s2">(</span><span class="s1">randomGroup</span><span class="s2">);</span>
        <span class="s1">System</span><span class="s2">.</span><span class="s1">out</span><span class="s2">.</span><span class="s1">println</span><span class="s2">(</span><span class="s3">&quot;随机抽取的小组中的学生: &quot; </span><span class="s2">+ </span><span class="s1">randomStudentFromGroup</span><span class="s2">.</span><span class="s1">getName</span><span class="s2">());</span>
        <span class="s5">//随机从班级抽取学生</span>
        <span class="s1">Student randomStudentFromClass </span><span class="s2">= </span><span class="s1">classRoom</span><span class="s2">.</span><span class="s1">getRandomStudentFromClass</span><span class="s2">();</span>
        <span class="s1">System</span><span class="s2">.</span><span class="s1">out</span><span class="s2">.</span><span class="s1">println</span><span class="s2">(</span><span class="s3">&quot;随机从全班抽取的学生: &quot; </span><span class="s2">+ </span><span class="s1">randomStudentFromClass</span><span class="s2">.</span><span class="s1">getName</span><span class="s2">());</span>
    <span class="s2">}</span>
<span class="s2">}</span>
</pre>
</body>
</html>